<?php


namespace App\Models;


use Base\BaseModel;
use Lib\DB;
use PDOStatement;

class GiveModel extends BaseModel
{
    protected $table = 'give';

    /**
     * 新增
     * @param $data
     * @return bool|PDOStatement
     */
    public function insertGive($data)
    {
        return $this->baseInsert($data);
    }

    /**
     * 分页获取列表
     * @param $where
     * @param int $page
     * @param int $limit
     * @param array $fields
     * @return array
     */
    public function getGiveListByPage($where, $page = 1, $limit = 20, $fields = '*')
    {
        $where['ORDER'] = ["create_time" => "DESC"];
        return $this->baseSelectByPage($where, $fields, $limit, $page) ?: [];
    }

    /**
     * 获取分页列表数量
     * @param $where
     * @return int
     */
    public function getGiveListCount($where)
    {
        return $this->baseSelectCount($where) ?: 0;
    }

    /**
     * 获取单行
     * @param $id
     * @param string $fields
     * @return array
     */
    public function getGiveRowById($id, $fields = '*')
    {
        return $this->baseSelectFirst($fields, [
            'id' => $id,
            'is_del' => 0
        ]);
    }

    public function fakeDeleteGive($id)
    {
        return $this->baseUpdate([
            'id' => $id
        ], [
            'is_del' => 1
        ]);
    }

    public function getGiveRow($id)
    {
        return $this->baseSelectFirst(
            '*',
            ['id' => $id, 'is_del' => 0]
        );
    }

    public function updateGive($where, $data)
    {
        return $this->baseUpdate($where, $data);
    }

    public function setGiveInc($where, $field)
    {
        return $this->baseInc($where, $field);
    }

    public function getGiveDir($giveIds)
    {
        return $this->baseCreateDictionary($giveIds, 'id', 'id', '*', []);
    }
}
